package com.project.controller;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.InventoryManagement.MoveBean;
import com.project.service.IMouseService;
import com.project.service.IMoveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.net.http.HttpRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("move")
public class MoveController {

    @Resource
    private IMoveService moveService;



    @RequestMapping("findMove")
    public IPage<MoveBean> findMove(@RequestParam(value = "pageNo",defaultValue = "1") int pageNo, @RequestParam(value = "pageSize",defaultValue = "3") int pageSize, LocalDate startDate, LocalDate endDate, String moveClass) {
        IPage<MoveBean> page = moveService.findMove(pageNo,pageSize,startDate,endDate,moveClass);


        return page;
    }


    //查询出库信息包含出库物品
    @RequestMapping("findMoveById")
    public MoveBean findMoveById(int moveId) {

        MoveBean moveBean = moveService.findMoveById(moveId);

        System.out.println(moveBean);

        return moveBean;

    }

    //根据领用班级查询出库信息包含出库商品
    @RequestMapping("findMoveMsg")
    public MoveBean findMoveMsg(String moveClass) {

        MoveBean moveBean = moveService.findMoveMsg(moveClass);

        return moveBean;

    }
    @RequestMapping("addMove")
    //如果没有相应的出库信息，新增出库信息
    public String addMove(MoveBean moveBean) {

        if (moveBean != null){
            moveService.addMove(moveBean);
        }
        return "ok";
    }
    //向出库内容添加物品
    @RequestMapping("addAgentia")
    public String addAgentia(Integer moveId, String ataArray,int detailsNum, HttpServletRequest request) {


        JSONArray jsonArray = JSONArray.parseArray(ataArray);

        for (Object o:jsonArray) {

            moveService.addAgentia(moveId, (Integer) o,detailsNum);

        }

       return "ok" ;
    }
    @RequestMapping("delAgentia")
    //根据出库信息id和物品id移除物品
    public String delAgentia(int moveId,int agentiaId) {

        moveService.delAgentia(moveId,agentiaId);
        return "ok" ;
    }

    @RequestMapping("updateNum")
    //根据出库信息id修改物品数量
    public String  updateNum(int moveId,int agentiaId,int detailsNum) {

        moveService.updateNum(moveId,agentiaId,detailsNum);

       return "ok" ;

    }
}
